Skip to content

Enable RestClientAutoConfiguration in reactive web applications when virtual threads are enabled #44952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

dmitrysulman
Copy link
Contributor

@dmitrysulman dmitrysulman commented Mar 30, 2025

This PR introduces NotReactiveWebApplicationOrVirtualThreadsEnabledCondition for use in RestClientAutoConfiguration.

Closes #44912

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 30, 2025
@philwebb philwebb changed the title Add NotReactiveWebApplicationOrVirtualThreadsEnabledCondition for RestClientAutoConfiguration Add NotReactiveWebApplicationOrVirtualThreadsEnabledCondition for RestClientAutoConfiguration Apr 1, 2025
@dmitrysulman
Copy link
Contributor Author

@philwebb just checking, does this PR align with what was raised in #44912?

@philwebb philwebb changed the title Add NotReactiveWebApplicationOrVirtualThreadsEnabledCondition for RestClientAutoConfiguration Enable RestClientAutoConfiguration in reactive web applications when virtual threads are enabled Apr 15, 2025
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 15, 2025
@philwebb philwebb added this to the 3.5.0-RC1 milestone Apr 15, 2025
@philwebb philwebb self-assigned this Apr 15, 2025
philwebb pushed a commit that referenced this pull request Apr 15, 2025
Refine `RestClientAutoConfiguration` conditional so that it
applies in reactive web applications if virtual threads are
active and a task executor is configured.

See gh-44952

Signed-off-by: Dmitry Sulman <[email protected]>
@philwebb philwebb closed this in f77f3c6 Apr 15, 2025
@philwebb
Copy link
Member

Thanks @dmitrysulman! I've merged this with one small amendment to try and also check that there's an applicationTaskExecutor bean. This should hopefully align with this code in WebFluxAutoConfiguration

@blake-bauman
Copy link

I'm curious as to why only when Virtual Threads are enabled. WebFlux can be configured with a ThreadPoolTaskExecutor for blocking execution using BlockingExecutionConfigurer.setExecutor(), which should be sufficient for a RestClient.

@philwebb
Copy link
Member

@blake-bauman We I looked at the PR I couldn't see an obvious way to tell if the BlockingExecutionConfigurer has been called. Looking again, we might be able to do that if WebFluxConfigurationSupport.getBlockingExecutionConfigurer() wasn't final. We could then return our own subclass and get access to BlockingExecutionConfigurer.getExecutor(). I'll open a Spring Framework issue to see if that's an option.

@philwebb
Copy link
Member

philwebb commented Apr 16, 2025

Actually, thinking about things some more, I'm not sure we can use a hook like that since we need to make our condition decision before the BlockingExecutionConfigurer is called. Perhaps we should also offer a property to enable support. @blake-bauman, feel free to open another issue if the virtual thread support isn't going to be enough.

@blake-bauman
Copy link

blake-bauman commented Apr 16, 2025

I think my main question is, what is the need to detect? Even if an app has Virtual Threads enabled, I don't believe the execution is offloaded to a Virtual Thread if the Controller method return type is Mono, and they try to use a RestClient. I believe that throws the same exception if they tried to use a RestClient on a non-Mono Controller method and they haven't configured the BlockingExecutionConfigurer. So, I'm mainly wondering if there's a benefit to trying to detect, or if we should just let them use it and it'll fail later without the proper setup.

(For reference, this is for apps which, for one reason or another, can't yet update to Java 21 and therefore can't enable Virtual Threads, but have used the ThreadPoolTaskExecutor for the BlockingExecutionConfigurer)

@philwebb philwebb added the for: team-meeting An issue we'd like to discuss as a team to make progress label Apr 16, 2025
@philwebb
Copy link
Member

@blake-bauman I'll need to discuss this with the team again to see and with some folks that have more knowledge of the reactive stack. I've flagged this one for our next meeting.

@blake-bauman
Copy link

For now, we've just copy/pasted the entire RestClientAutoConfiguration internally without the conditions in order to unblock, so that we can get the Micrometer enrichments for RestClients.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-meeting An issue we'd like to discuss as a team to make progress type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable RestClientAutoConfiguration in reactive web applications when virtual threads are enabled
4 participants